def check(listOfNumber):
    strList = (str(n) for n in listOfNumber)
    f = []
    for s in strList:
        t = list(s)
        t.sort()
        t = ''.join(t)
        f.append(t)
    c = f[0]
    for t in f:
        if not c == t:
            return False
    return True

MAX = 10000000

for i in xrange(1, MAX):
    l = [i * j for j in xrange(1, 7)]
    if check(l):
        print i
        break


